﻿@{
	ViewData["Title"] = "RawMaterialUpdate";
	Layout = "~/Views/Home/Menu.cshtml";
}

<h1>RawMaterialUpdate</h1>

<form class="layui-form" action="">
	<div class="layui-form-item">
		<label class="layui-form-label">原料编号</label>
		<div class="layui-input-inline layui-input-wrap;line - spacing:600">
			<input type="text" name="rawMaterialNumbering" id="rawMaterialNumbering" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
		</div>

		<label class="layui-form-label">原料名称</label>
		<div class="layui-input-inline layui-input-wrap">
			<input type="text" name="rawMaterialName" id="rawMaterialName" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">原料分类</label>
		<div class="layui-input-inline layui-input-wrap;line - spacing:600">
			<select name="rawMaterialClassify" id="rawMaterialClassify" lay-verify="required" lay-search>
				<option value="">请选择</option>
				<option value="五金">五金</option>
			</select>
		</div>

		<label class="layui-form-label">尺寸</label>
		<div class="layui-input-inline layui-input-wrap">
			<select name="rawMaterialSize" id="rawMaterialSize" lay-verify="required" lay-search>
				<option value="">请选择</option>
				<option value="8mm">8mm</option>
				<option value="10mm">10mm</option>
				<option value="12mm">12mm</option>
				<option value="14mm">14mm</option>
				<option value="16mm">16mm</option>
				<option value="18mm">18mm</option>
				<option value="20mm">20mm</option>
			</select>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">规格型号</label>
		<div class="layui-input-inline layui-input-wrap;line - spacing:600">
			<select name="rawMaterialSpecModel" id="rawMaterialSpecModel" lay-verify="required" lay-search>
				<option value="">请选择</option>
				<option value="M8">M8</option>
				<option value="M10">M10</option>
				<option value="M12">M12</option>
				<option value="M14">M14</option>
				<option value="M16">M16</option>
				<option value="M18">M18</option>
				<option value="M20">M20</option>
			</select>

		</div>

		<label class="layui-form-label">原料属性</label>
		<div class="layui-input-inline layui-input-wrap">
			<select name="rawMaterialAttribute" id="rawMaterialAttribute" lay-verify="required" lay-search>
				<option value="">请选择</option>
				<option value="采购">采购</option>
				<option value="自制">自制</option>
			</select>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">单位</label>
		<div class="layui-input-inline layui-input-wrap;line - spacing:600">
			<select name="rawMaterialUnit" id="rawMaterialUnit" lay-verify="required" lay-search>
				<option value="">请选择</option>
				<option value="个">个</option>
				<option value="箱">箱</option>
				<option value="件">件</option>
				<option value="套">套</option>
				<option value="台">台</option>
			</select>

		</div>

		<label class="layui-form-label">库存数量</label>
		<div class="layui-input-inline layui-input-wrap">
			<input type="text" name="rawMaterialinventory" id="rawMaterialinventory" lay-verify="required" autocomplete="off" lay-affix="number" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">原料类型</label>
		<div class="layui-input-inline layui-input-wrap;line - spacing:600">
			<select name="rawMaterialType" id="rawMaterialType" lay-verify="required" lay-search>
				<option value="">请选择</option>
				<option value="半成品">半成品</option>
				<option value="成品">成品</option>
				<option value="原料">原料</option>
			</select>

		</div>

		<label class="layui-form-label">状态</label>
		<div class="layui-input-inline layui-input-wrap">
			<input type="radio" name="rawMaterilStatus" id="rawMaterilStatus" value="禁用" title="禁用" checked>
			<input type="radio" name="rawMaterilStatus" id="rawMaterilStatus" value="启用" title="启用">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">原料数量</label>
		<div class="layui-input-inline layui-input-wrap;line - spacing:500">
			<input type="text" name="rawMaterialNumber" id="rawMaterialNumber" lay-verify="required" autocomplete="off" lay-affix="number" class="layui-input">
		</div>

		<label class="layui-form-label">报警天数</label>
		提前<div class="layui-inline">
			<div class="layui-input-inline layui-input-wrap" style="width: 100px;">
				<input type="number" name="rawMaterialDay" id="rawMaterialDay" placeholder="" autocomplete="off" class="layui-input" min="0" step="1" lay-affix="number">
			</div>
		</div>天报警
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">库存上限</label>
		<div class="layui-input-inline layui-input-wrap;line - spacing:600">
			<input type="text" name="inventoryMaximums" id="inventoryMaximums" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
		</div>

		<label class="layui-form-label">库存下限</label>
		<div class="layui-input-inline layui-input-wrap">
			<input type="text" name="inentoryLower" id="inentoryLower" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">原料位置</label>
		<div class="layui-input-inline layui-input-wrap;line - spacing:600">
			<input type="text" name="rawMateriallocation" id="rawMateriallocation" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
		</div>

		<label class="layui-form-label">创建时间</label>
		<div class="layui-input-inline layui-input-wrap">
			<div class="layui-input-prefix">
				<i class="layui-icon layui-icon-date"></i>
			</div>
			<input type="date" name="rawMaterialDate" id="rawMaterialDate" autocomplete="off" lay-verify="required" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item layui-form-text">
		<label class="layui-form-label">备注</label>
		<div class="layui-input-block" style="width:600Px">
			<textarea name="rawMaterialReamrk" id="rawMaterialReamrk" placeholder="请输入内容" class="layui-textarea"></textarea>
		</div>
	</div>
	<div class="layui-form-item">
		<button type="submit" class="layui-btn" lay-submit lay-filter="formDemo">修改</button>
		<button type="reset" class="layui-btn" onclick="location.href='/RawMaterial/RawMaterialShow'">返回</button>
	</div>
</form>
<script>
	//文档就绪函数
	$(function () {
		fantian()
	})
	var obj = {
		rawMaterialId: 0,
		rawMaterialNumbering: "",
		rawMaterialName: "",
		rawMaterialClassify: "",
		rawMaterialSize: "",
		rawMaterialSpecModel: "",
		rawMaterialAttribute: "",
		rawMaterialUnit: "",
		rawMaterialinventory: 0,
		rawMaterialType: "",
		rawMaterilStatus: "",
		rawMaterialNumber: 0,
		rawMaterialDay: 0,
		inventoryMaximums: 0,
		inentoryLower: 0,
		rawMateriallocation: "",
		rawMaterialDate: "",
		rawMaterialReamrk: "",
		rawMaterialImage: "",
		addName: "",
		addTime: "",
	}
	function fantian() {
		return new Promise(function (resolve, reject) {
			$(document).ready(function () {
				// 获取要编辑的用户ID，可以通过URL参数或者其他方式获取，这里假设通过URL参数获取
				var rawMaterialId = localStorage.getItem("rawMaterialId");
				console.log(rawMaterialId);
				// 如果获取到了用户ID，就去后台获取该用户的详细信息并反填到表单
				if (rawMaterialId) {
					$.ajax({
						type: "get",
						url: "/RawMaterial/RawMaterMondel",
						data: {
							rawMaterialId: rawMaterialId
						},
						success: function (res) {
							var resse = JSON.parse(res)
							console.log(resse)
							if (resse.data) {
								const s = resse.data;
								//反填日期框
								var da = new Date(s.rawMaterialDate);
								// 获取年、月、日
								var year = da.getFullYear();
								var month = (da.getMonth() + 1).toString().padStart(2, '0');  // 月份从0开始，因此加1
								var day = da.getDate().toString().padStart(2, '0');  // 补充两位数字
								// 拼接成 "yyyy-MM-dd" 格式
								var formattedDate = `${year}-${month}-${day}`;
								console.log(formattedDate)
								$('#rawMaterialId').val(s.rawMaterialId);
								$('#rawMaterialNumbering').val(s.rawMaterialNumbering);
								$('#rawMaterialName').val(s.rawMaterialName);
								$('#rawMaterialClassify').val(s.rawMaterialClassify);
								layui.form.render('select')
								$('#rawMaterialSize').val(s.rawMaterialSize);
								layui.form.render('select')
								$('#rawMaterialSpecModel').val(s.rawMaterialSpecModel);
								layui.form.render('select')
								$('#rawMaterialAttribute').val(s.rawMaterialAttribute);
								layui.form.render('select')
								$('#rawMaterialUnit').val(s.rawMaterialUnit);
								layui.form.render('select')
								$('#rawMaterialinventory').val(s.rawMaterialinventory);
								$('#rawMaterialType').val(s.rawMaterialType);
								layui.form.render('select')
								$('#rawMaterilStatus').val(s.rawMaterilStatus);
								//是否禁用
								var lswarehouseState = s.rawMaterilStatus
								$("[name='rawMaterilStatus']").each(function () {
									if (lswarehouseState.toString() == $(this).val()) {
										$(this).prop("checked", true);
									}
								})
								$('#rawMaterialNumber').val(s.rawMaterialNumber);
								$('#rawMaterialDay').val(s.rawMaterialDay);
								$('#inventoryMaximums').val(s.inventoryMaximums);
								$('#inentoryLower').val(s.inentoryLower);
								$('#rawMateriallocation').val(s.rawMateriallocation);
								$('#rawMaterialDate').val(formattedDate);
								$('#rawMaterialReamrk').val(s.rawMaterialReamrk);
								$('#rawMaterialImage').val(s.rawMaterialImage);
								$('#addName').val(s.addName);
								$('#addTime').val(s.addTime);
								obj.rawMaterialId = s.rawMaterialId,
									obj.rawMaterialNumbering = s.rawMaterialNumbering,
									obj.rawMaterialName = s.rawMaterialName,
									obj.rawMaterialClassify = s.rawMaterialClassify,
									obj.rawMaterialSize = s.rawMaterialSize,
									obj.rawMaterialSpecModel = s.rawMaterialSpecModel,
									obj.rawMaterialAttribute = s.rawMaterialAttribute,
									obj.rawMaterialUnit = s.rawMaterialUnit,
									obj.rawMaterialinventory = s.rawMaterialinventory,
									obj.rawMaterialType = s.rawMaterialType,
									obj.rawMaterilStatus = s.rawMaterilStatus,
									obj.rawMaterialNumber = s.rawMaterialNumber,
									obj.rawMaterialDay = s.rawMaterialDay,
									obj.inventoryMaximums = s.inventoryMaximums,
									obj.inentoryLower = s.inentoryLower,
									obj.rawMateriallocation = s.rawMateriallocation,
									obj.rawMaterialDate = s.rawMaterialDate,
									obj.rawMaterialReamrk = s.rawMaterialReamrk,
									obj.rawMaterialImage = s.rawMaterialImage,
									obj.addName = s.addName,
									obj.addTime = s.addTime

							}
						}
					})
				}
			});
		});
	};

	var obj1 = {
		rawMaterialId: 0,
		rawMaterialNumbering: "",
		rawMaterialName: "",
		rawMaterialClassify: "",
		rawMaterialSize: "",
		rawMaterialSpecModel: "",
		rawMaterialAttribute: "",
		rawMaterialUnit: "",
		rawMaterialinventory: 0,
		rawMaterialType: "",
		rawMaterilStatus: "",
		rawMaterialNumber: 0,
		rawMaterialDay: 0,
		inventoryMaximums: 0,
		inentoryLower: 0,
		rawMateriallocation: "",
		rawMaterialDate: "",
		rawMaterialReamrk: "",
		rawMaterialImage: "",
		addName: "",
		addTime: "",
	}
	console.log(obj1)
	layui.use(['layer', 'form', 'util'], function () {
		var layer = layui.layer;
		var $ = layui.jquery;
		var form = layui.form;
		var util = layui.util;

		form.on('submit(formDemo)', function (data) {
			var field = data.field; // 获取表单字段值
				obj1.rawMaterialId = obj.rawMaterialId,
				obj1.rawMaterialNumbering = field.rawMaterialNumbering,
				obj1.rawMaterialName = field.rawMaterialName,
				obj1.rawMaterialClassify = field.rawMaterialClassify,
				obj1.rawMaterialSize = field.rawMaterialSize,
				obj1.rawMaterialSpecModel = field.rawMaterialSpecModel,
				obj1.rawMaterialAttribute = field.rawMaterialAttribute,
				obj1.rawMaterialUnit = field.rawMaterialUnit,
				obj1.rawMaterialinventory = field.rawMaterialinventory,
				obj1.rawMaterialType = field.rawMaterialType,
				obj1.rawMaterilStatus =     $('#rawMaterilStatus').is(':checked ' )   ? "禁用":  "启用",
				obj1.rawMaterialNumber = field.rawMaterialNumber,
				obj1.rawMaterialDay = field.rawMaterialDay,
				obj1.inventoryMaximums = field.inventoryMaximums,
				obj1.inentoryLower = field.inentoryLower,
				obj1.rawMateriallocation = field.rawMateriallocation,
				obj1.rawMaterialDate = field.rawMaterialDate,
				obj1.rawMaterialReamrk = field.rawMaterialReamrk,
				obj1.rawMaterialImage = obj.rawMaterialImage,
				obj1.addName = obj.addName,
				obj1.addTime = obj.addTime,
				console.log(obj1)
				// 显示填写结果，仅作演示用
				// 此处可执行 Ajax 等操作
				debugger
				$.ajax({
				url: '/RawMaterial/RawMaterUpdate',
					type: 'post',
					data: {dto:obj1,token: localStorage.getItem("token")},
					success: function (res) {
						var res = JSON.parse(res)
						console.log(obj1);
						console.log(res);
					if (res.data == 1) {
							layer.msg("修改成功", { icon: 1 })
							setTimeout(function () {
							location.href = '/RawMaterial/RawMaterialShow'
							}, 2000);
						} else {
							layer.msg("修改失败:" + res.message, { icon: 2 });
						}
					}
				});

			return false; // 阻止默认 form 跳转
		});
		// 对弹层中的表单进行初始化渲染
		form.render();
	});
</script>
<script src="~/js/rawmaterialcontroller1/rawmaterialjs.js"></script>
